package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.activity.TeaDetailActivity;
import com.example.a14110100409.yuejiandemo.config.Config;
import com.example.a14110100409.yuejiandemo.javabean.TeaList;
import com.example.a14110100409.yuejiandemo.utils.RoundImageView;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


/**
 * Created by Administrator on 2017/9/30 0030.
 */

public class TeaAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<TeaList> list;
    public TeaAdapter(Context context, List<TeaList> list)//绑定adapter时传的两个参数
    {
        this.context=context;
        this.list=list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_of_teacher,viewGroup,false);
        TeaViewHolder holder=new TeaViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        final TeaList teaList=list.get(i);
        TeaViewHolder holder=(TeaViewHolder)viewHolder;
        holder.hint.setText(teaList.getHits());
        holder.name.setText(teaList.getRealname());
        Picasso.with(context).load(Config.PIC_URL+teaList.getThumb()).into(holder.pic);
        ((TeaViewHolder) viewHolder).pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, TeaDetailActivity.class);
                intent.putExtra("tea_id",teaList.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class  TeaViewHolder extends RecyclerView.ViewHolder
    {
        RoundImageView pic;
        TextView name;
        TextView hint;
        public TeaViewHolder(View itemView) {
            super(itemView);
            pic=(RoundImageView)itemView.findViewById(R.id.tea_list_pic);
            name=(TextView)itemView.findViewById(R.id.tea_list_name);
            hint=(TextView)itemView.findViewById(R.id.tea_list_hint);
        }
    }
}
